{$X-}
{$R-}
{$D-}

Program SineGrid;

   USES {$U-}
      {$U obj/Memtypes   } Memtypes,
      {$U obj/QuickDraw  } QuickDraw,
      {$U obj/OSIntf     } OSIntf,
      {$U obj/ToolIntf   } ToolIntf,
      {$U obj/FixMath    } FixMath,
      {$U obj/Graf3D     } Graf3D;

{Note: This file must be linked with obj/FixMath, obj/FixAsm, and obj/Graf3D.
       To build using example/exec, link using example/Graf3DLink.}

   CONST
      XLB = -10;
      XUB =  10;
      YLB = -10;
      YUB =  10; {array bounds}
      keyOrMouse = mDownMask + keyDownMask;

   VAR
      gPort:   GrafPort;
      gPort3D:   Port3d;
      data: ARRAY [XLB..XUB, YLB..YUB] OF Fixed;
      dummy: EventRecord;

   PROCEDURE CalcData;
   VAR
      ix,
      iy: INTEGER;
   BEGIN
      FOR ix := XLB TO XUB DO
      BEGIN
         FOR iy := YLB TO YUB DO
            data[ix, iy] := FixDiv(FracSin(FixRatio(ix, 3)) +
             FracCos(FixRatio(iy, 4)), 1073741824);
      END
   END;

   PROCEDURE PlotGrid;
   CONST
      fYLB = YLB * 65536;
      fXLB = XLB * 65536;
   VAR
      ix,
      iy: INTEGER;
   BEGIN
      FOR ix := XLB TO XUB DO
      BEGIN
         MoveTo3D(FixRatio(ix, 1), fYLB, data[ix, YLB]);
         FOR iy := YLB TO YUB DO
            LineTo3D(FixRatio(ix, 1), FixRatio(iy, 1), data[ix, iy]);
      END;
      FOR iy := YLB TO YUB DO
      BEGIN
         MoveTo3D(fXLB, FixRatio(iy, 1), data[XLB, iy]);
         FOR ix := XLB TO XUB DO
            LineTo3D(FixRatio(ix, 1), FixRatio(iy, 1), data[ix, iy]);
      END;
   END;

BEGIN
{initialization routines}
   InitGraf(@thePort);
   InitCursor;
   HideCursor;
   OpenPort(@gPort);
   Open3DPort(@gPort3D);
{program begins}
   CalcData;
   PenPat(White);
   BackPat(Black);
   EraseRect(gPort.portRect);
   FrameRect(gPort.portRect);
   LookAt(-983040, 655360, 983040, -655360); {LookAt (-15, 10, 15, -10)};
   ViewAngle(1966080); {ViewAngle(30)}
   Scale(65536, 65536, 196608); {Scale(1, 1, 3)}
   Roll(1966080); {Roll(30)}
   Pitch(4587520); {Pitch(70)}
   PlotGrid;

   WHILE NOT OSEventAvail(keyOrMouse, dummy) DO;
END.

